// 路由聚合模块
mod auth;
mod user;
mod error;

use axum::Router;
use axum::routing::get;
use crate::services::auth::AuthService;
use crate::services::user::UserService;

// 聚合所有路由
// 在路由定义中注入服务
// 参考 https://docs.rs/axum/latest/axum/struct.Router.html#method.nest
pub fn create_router(auth_service: AuthService, user_service: UserService) -> Router {
    // 公共前缀路由
    let api_v1 = Router::new()
        .nest("/auth", auth::routes())    // /api/v1/auth/...
        .nest("/users", user::routes())            // /api/v1/users/...
        .with_state((auth_service, user_service));

    Router::new()
        .route("/", get(hello))  // 根路由 /
        .nest("/api/v1", api_v1)           // 带前缀的路由组
}

// 根路由处理函数
async fn hello() -> &'static str { "Hello World 2025" }